/**
 * 商机管理管理初始化
 */
var Bopportunities = {
    id: "BopportunitiesTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
Bopportunities.initColumn = function () {
    return [
        {field: 'selectItem', radio: true},
            {title: '客户编号', field: 'id', visible: true, align: 'center', valign: 'middle'},
            {title: '客户名称', field: 'name', visible: true, align: 'center', valign: 'middle'},
            {title: '客户状态', field: 'nstatus', visible: true, align: 'center', valign: 'middle'},
            {title: '行业', field: 'industry', visible: true, align: 'center', valign: 'middle'},
            {title: '省份', field: 'province', visible: true, align: 'center', valign: 'middle'},
            {title: '地级市', field: 'city', visible: true, align: 'center', valign: 'middle'},
            {title: '区县', field: 'area', visible: true, align: 'center', valign: 'middle'},
            {title: '客户规模', field: 'sizes', visible: true, align: 'center', valign: 'middle'},
            {title: '团队', field: 'team', visible: true, align: 'center', valign: 'middle'},
            {title: '销售员', field: 'salesman', visible: true, align: 'center', valign: 'middle'},
            {title: '年购买潜力（万元）', field: 'potential', visible: true, align: 'center', valign: 'middle'},
            {title: '预计采购额（万元）', field: 'amount', visible: true, align: 'center', valign: 'middle'},
            {title: '预计采购时间', field: 'amounttime', visible: true, align: 'center', valign: 'middle'},
            {title: '销售状态', field: 'astatus', visible: true, align: 'center', valign: 'middle'}
    ];
};

/**
 * 检查是否选中
 */
Bopportunities.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if(selected.length == 0){
        Feng.info("请先选中表格中的某一记录！");
        return false;
    }else{
        Bopportunities.seItem = selected[0];
        return true;
    }
};

/**
 * 点击添加商机管理
 */
Bopportunities.openAddBopportunities = function () {
    var index = layer.open({
        type: 2,
        title: '添加商机管理',
        area: ['800px', '420px'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/bopportunities/bopportunities_add'
    });
    this.layerIndex = index;
};

/**
 * 打开查看商机管理详情
 */
Bopportunities.openBopportunitiesDetail = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '商机管理修改',
            area: ['800px', '420px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/bopportunities/bopportunities_update/' + Bopportunities.seItem.id
        });
        this.layerIndex = index;
    }
};
/**
 * 打开查看商机管理详情
 */
Bopportunities.openBopportunitiesDetails = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '商机管理详情',
            area: ['800px', '420px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/bopportunities/bopportunities_detail/' + Bopportunities.seItem.id
        });
        this.layerIndex = index;
    }
};
/**
 * 删除商机管理
 */
Bopportunities.delete = function () {
    if (this.check()) {
        var ajax = new $ax(Feng.ctxPath + "/bopportunities/delete", function (data) {
            Feng.success("删除成功!");
            Bopportunities.table.refresh();
        }, function (data) {
            Feng.error("删除失败!" + data.responseJSON.message + "!");
        });
        ajax.set("bopportunitiesId",this.seItem.id);
        ajax.start();
    }
};

/**
 * 查询商机管理列表
 */
Bopportunities.search = function () {
    var queryData = {};
    queryData['condition'] = $("#condition").val();
    Bopportunities.table.refresh({query: queryData});
};

$(function () {
    var defaultColunms = Bopportunities.initColumn();
    var table = new BSTable(Bopportunities.id, "/bopportunities/list", defaultColunms);
    table.setPaginationType("client");
    Bopportunities.table = table.init();
});
